<template>
  <div>
    <el-row>
        <b>到访状态：</b>
        <el-radio-group v-model="radio1" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">已到访</el-radio-button>
        <el-radio-button label="2">未到访</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="placesToVisit"
        label="到达地点">
      </el-table-column>
      <el-table-column
        prop="accessApplications"
        label="申请人">
      </el-table-column>
      <el-table-column
        prop="visitorSalutation"
        label="访客称呼">
      </el-table-column>
      <el-table-column
        prop="registerSource"
        label="登记来源">
        <template slot-scope="scope">
            <el-tag v-if="scope.row.registerSource == 1">物业登记</el-tag>
            <el-tag v-if="scope.row.registerSource == 2">业主登记</el-tag>
            <el-tag v-if="scope.row.registerSource == 3">未登记</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="status"
        label="状态">
        <template slot-scope="scope">
            <el-tag :type="scope.row.tagColor">{{ scope.row.status==1?'未到访':'已到访' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="applicationTimeline"
        label="登记时间">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="申请时间">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-search" @click="dit(scope.row.id)">确认到访</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
    name:'visitor',
    data(){
        return{
            radio1:'0',
            variety:'',
            color:'',
            tableData: [],
            currentPage:1,
            pageSize:10,
            total:0,
        }
    },
    created(){this.initAuthority()},
    methods:{
      initAuthority(){
        this.$request.get("/role/authority",{
          params:{
            id: JSON.parse(localStorage.getItem("admin")).id,
            index: 16
          }
        })
        .then(res =>{
          this.Authority = res.data
          if(res.data == '1'){
            this.initTable()
          }else{
            this.$message.error("你没有权限访问此功能")
            // this.$router.push("/")
          }
        })
        .catch(err =>{
          console.log(err)
        })

      },
      dit(id){
        this.$request.post("/visitor/cgstatus",{
              id:id
        }).then(res=>{
            this.initTable()
        }).catch(err=>{
            console.error(err)
        })  
      },
      handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pageSize = val
            this.initTable()
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.currentPage = val
            this.initTable()
        },
        initTable(){
            this.$request.get("/visitor/page",{
                params:{
                    page: this.currentPage,
                    size: this.pageSize,
                    status:this.radio1,
                }
            }).then(res => {
                this.tableData = res.data.records
                this.total = res.data.total
            }).catch(err =>{
                console.log(err)
            })
        },
    }
}
</script>

<style>
    .el-row{
        margin-bottom: 20px;
    }
</style>